package com.dhgate.spu.analysis.script;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import com.dhgate.spu.analysis.consts.SysConsts;
import com.dhgate.spu.analysis.init.InitDbConfig;
import com.dhgate.spu.analysis.init.InitParameter;

/** 
 * @author:       
 * @create:      2014-2-25 上午11:09:34 
 * @description: 处理业务整理的品牌和型号的对应关系为标准格式
 * 标准格式:attrValId:enName:cnName:model1,model2,model3
 * 例如:1188281:Meizu:魅族:M8,M9,MX,MX2,MX3
 */
public class ArrangeBrandModelMain {
	public static void main(String[] args) throws Exception {
		System.out.println("ArrangeBrandModel begin");
		//初始化基本配置参数
		InitParameter.init();
		//读取数据库初始化配置
		InitDbConfig.init();
		//组织oracle产品属性
		
		
		String projectPath = System.getProperty("user.dir");
		String xmlAbsolutePath = projectPath + SysConsts.FILE_SEPARATOR + "conf"+SysConsts.FILE_SEPARATOR+"newbrand.txt";
		loadFile(xmlAbsolutePath);
		
		System.out.println("ArrangeBrandModel end");
		
		
	}

	
	private static void loadFile(String filePath) {
		InputStreamReader fr;
		try {
			fr = new InputStreamReader(new FileInputStream(filePath));
			BufferedReader br = new BufferedReader(fr);
			String line = br.readLine();
			while (line != null) {
				String array[] = line.split(",");
				
				String cnBrandName = array[0].trim();
				String enBrandName = array[1].trim();
				
				String newline = enBrandName+":"+cnBrandName+":";
				StringBuffer modelSB = new StringBuffer();
				if(array.length > 2){
					for(int i=2; i<array.length; i++){
						modelSB.append(array[i].trim()+",");
					}
					newline = newline + modelSB.substring(0,modelSB.length()-1);
				}

				line = br.readLine();
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	
	}
	
	
	
}
